<template>
  <div style="width: 98%; margin: 0 auto">
    <el-row>
      <el-col :span="10">
        <div style="float: left; padding-right: 20px">
          <el-button
            icon="el-icon-plus"
            type="success"
            :hidden="permissions[0] != 'group'"
            @click="handleAddInfo"
          >
            添加{{ currentResourceTypeTitle }}
          </el-button>
        </div>

        <div style="float: left">
          <el-button type="primary" @click="searchAllFreeResource">
            所有空闲资源
          </el-button>
        </div>

        <div style="float: left; margin-left: 20px">
          <el-button type="primary" @click="searchAllCouldApplyResource">
            所有可申请资源
          </el-button>
        </div>
      </el-col>

      <el-col :span="14">
        <div style="float: right; margin-bottom: 10px">
          <el-button type="primary" @click="handleControllerColumnsShow">
            自定义展示列头
          </el-button>
        </div>

        <div
          style="float: right; margin-right: 20px; margin-bottom: 10px"
          v-if="showSearchComponent"
        >
          <el-popover placement="bottom-end" trigger="click">
            <el-row>
              <SearchFormComponent
                :key="timer"
                @query-entity-list="queryEntityList"
                :resourceTypeName="currentResourceTypeName"
              ></SearchFormComponent>
            </el-row>
            <el-button type="primary" icon="el-icon-search" slot="reference">
              搜索
            </el-button>
          </el-popover>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-tabs
        v-model="currentResourceTypeIndex"
        type="border-card"
        @tab-click="handleTabChange"
      >
        <el-tab-pane
          v-for="resourceType in resourceTypeList"
          :key="resourceType.resourceTypeName"
          :label="resourceType.resourceTypeTitle"
        >
          <el-row>
            <el-table
              v-if="isShow"
              ref="table"
              :data="
                resourceTypeEntityDataList == null
                  ? []
                  : resourceTypeEntityDataList
              "
              border
              :header-cell-style="getHeadClass"
              :row-class-name="getRowClassName"
              empty-text="当前没有数据，请添加数据"
            >
              <el-table-column
                v-for="header in headDatas"
                :label="header.label"
                :prop="header.prop"
                :width="header.width"
                :key="header.prop"
                :sortable="header.sort == 'true' ? true : false"
                :align="header.align"
                :formatter="
                  header.prop == 'mayApply'
                    ? formatterMayApply
                    : formatterNothing
                "
                show-overflow-tooltip
              ></el-table-column>
              <el-table-column
                show-overflow-tooltip
                align="center"
                width="120"
                label="操作"
              >
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    @click="handleEditInfo(scope.$index, scope.row)"
                  >
                    编辑
                  </el-button>
                  &emsp;&emsp;
                  <template
                    v-if="
                      permissions[0] === 'admin' ||
                      scope.row.createdBy === realName
                    "
                  >
                    <el-popconfirm
                      @onConfirm="handleDeleteEntity(scope.$index, scope.row)"
                      title="确认删除该实体么？"
                    >
                      <el-button
                        slot="reference"
                        type="text"
                        style="color: red"
                      >
                        删除
                      </el-button>
                    </el-popconfirm>
                  </template>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination
              hide-on-single-page
              background
              :current-page="pageData.currentPage"
              :layout="layout"
              :page-sizes="[5, 10, 20, 50, 100]"
              :page-size="pageData.pageSize"
              :total="pageData.total"
              @current-change="handleCurrentChange"
              @size-change="handleSizeChange"
            ></el-pagination>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-row>

    <!-- 这里是修改实体弹窗 -->
    <el-dialog
      :title="dialogTitle"
      @closed="getResourceTypeEntityDataList"
      :visible.sync="editResourceEntityDialogForm"
    >
      <el-form
        ref="editResourceEntityData"
        :label-width="formLabelWidth"
        :model="editResourceEntityData"
        style="width: 80%; margin: 0 auto"
      >
        <el-form-item label="实体类别" prop="resourceTypeTitle">
          <el-input
            v-model="editResourceEntityData.resourceTypeTitle"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item
          label="实体描述"
          :rules="[{ required: true, message: '请完善实体描述信息' }]"
          prop="resourceTypeEntityDescription"
        >
          <el-input
            v-model="editResourceEntityData.resourceTypeEntityDescription"
            placeholder="请输入实体描述"
            :disabled="permissions[0] != 'admin'"
          ></el-input>
        </el-form-item>
        <el-form-item label="是否可申请" prop="mayApply">
          <el-select
            v-model="editResourceEntityData.mayApply"
            :disabled="permissions[0] != 'admin'"
            placeholder="请选择是否可申请"
          >
            <el-option label="是" :value="true"></el-option>
            <el-option label="否" :value="false"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          v-for="item in resourceTypeEntityFieldList"
          :prop="item.resourceTypeFieldName"
          :label="
            item.resourceTypeFieldUnit != null &&
            item.resourceTypeFieldUnit != ''
              ? item.resourceTypeFieldTitle +
                '(' +
                item.resourceTypeFieldUnit +
                ')'
              : item.resourceTypeFieldTitle
          "
          :key="item.resourceTypeFieldId"
          :rules="[
            {
              required: item.resourceTypeFieldRequired,
              message: '请完善' + item.resourceTypeFieldTitle + '信息',
            },
          ]"
        >
          <el-input
            v-if="item.resourceTypeFieldType != 'enum'"
            v-model="editResourceEntityData[item.resourceTypeFieldName]"
            :placeholder="'请输入' + item.resourceTypeFieldTitle"
            :disabled="permissions[0] != 'admin'"
          ></el-input>
          <el-select
            v-else
            v-model="editResourceEntityData[item.resourceTypeFieldName]"
            placeholder="请选择"
            :disabled="permissions[0] != 'admin'"
          >
            <el-option
              v-for="enumItem in item.enumItemList"
              :key="enumItem.enumItemId"
              :label="enumItem.enumItemValue"
              :value="enumItem.enumItemKey"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="实体状态"
          :rules="[{ required: true, message: '请完善实体状态信息' }]"
          prop="status"
        >
          <el-select
            v-model="editResourceEntityData.status"
            placeholder="请选择实体状态"
          >
            <el-option
              v-for="status in usingStatus"
              :key="status.key"
              :label="status.value"
              :value="status.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="使用人">
          <el-cascader
            v-model="editResourceEntityData.owner"
            :options="userList"
            clearable
            :props="{ expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="editResourceEntityDialogForm = false">
          取消
        </el-button>
        <el-button type="primary" @click="handleSubmitResourceEntityData">
          提交
        </el-button>
      </div>
    </el-dialog>

    <!-- 设置自定义列头信息弹窗 -->
    <el-dialog
      title="列头展示设置"
      :visible.sync="controlCustomizeColumnDialogForm"
    >
      <el-form>
        <el-table
          :data="defaultCustomizeColumnList"
          ref="customizeColumnList"
          @selection-change="handleColumnSelectionChange"
        >
          <el-table-column
            type="selection"
            width="30"
            align="center"
          ></el-table-column>
          <el-table-column
            label="列名"
            prop="label"
            align="center"
          ></el-table-column>
          <el-table-column label="宽度" align="center">
            <template slot-scope="scope">
              <el-form-item style="margin-top: 18px" label-width="20px">
                <el-input
                  v-model="scope.row.width"
                  placeholder="请输入50、100、120等数字"
                  value="scope.row.width"
                ></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="可排序" prop="sort" align="center">
            <template slot-scope="scope">
              <el-form-item style="margin-top: 18px" label-width="20px">
                <el-select
                  v-model="scope.row.sort"
                  placeholder="请选择列是否可排序"
                >
                  <el-option value="true" label="是"></el-option>
                  <el-option value="false" label="否"></el-option>
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
        </el-table>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="controlCustomizeColumnDialogForm = false">
          取消
        </el-button>
        <el-button @click="handleDeleteCustomizeColumn">恢复默认</el-button>
        <el-button type="primary" @click="handleUpdateCustomizeColumn">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as EnumApi from "@/api/enum";
  import * as UserEntityApi from "@/api/userEntity";
  import * as UserApi from "@/api/user";
  import * as UserGroupApi from "@/api/userGroup";
  import * as CustomizeColumnApi from "@/api/customizeColumn";
  import * as ResourceTypeApi from "@/api/resourceType";
  import * as ResourceTypeFieldApi from "@/api/resourceTypeField";
  import * as ResourceTypeEntityApi from "@/api/resourceTypeEntity";
  import * as ResourceTypeEntityDataApi from "@/api/resourceTypeEntityData";
  import * as GroupResourceApi from "@/api/groupResource";
  import { usingStatus } from "@/config/settings";
  import { mapGetters } from "vuex";

  import SearchFormComponent from "@/views/pages/components/SearchFormComponent";

  export default {
    data() {
      return {
        // 资源实体数据列表
        resourceTypeEntityDataList: [],
        // 资源实体查询条件
        queryParam: {},

        isShow: true,

        // 资源字段实体列表
        resourceTypeEntityFieldList: [],

        // 资源类别列表
        resourceTypeList: [],
        // 当前展示资源类别下标
        currentResourceTypeIndex: 0,
        // 当前资源类别英文名
        currentResourceTypeName: "",
        currentResourceTypeTitle: "",

        // 分页设置
        layout: "total, sizes, prev, pager, next, jumper",
        pageData: {
          currentPage: 1,
          pageSize: 20,
          total: 0,
        },

        // 控制弹窗用来添加还是修改,默认修改
        addOrUpdate: "update",
        dialogTitle: "修改实体信息",

        // 修改信息弹窗
        editResourceEntityDialogForm: false,
        editResourceEntityData: {},
        // form表格label宽度
        formLabelWidth: "180px",
        // 用户列表
        userList: [],
        // 实体使用状态
        usingStatus: [],

        // 控制搜索按钮显示或隐藏
        showSearchComponent: false,
        timer: "now",

        // 列表头信息
        headDatas: [],
        // 控制列头弹窗显示消失
        controlCustomizeColumnDialogForm: false,
        // 所有可选列头数据列表
        allCustomizeColumnList: [],
        // 选中的列头数据列表
        multipleSelectionColumnList: [],
        // 默认展示的列头信息
        defaultCustomizeColumnList: [],
      };
    },

    props: ["userGroupName"],
    components: { SearchFormComponent },
    inject: ["reload"],

    methods: {
      // 控制列头设置弹窗显示与消失
      handleControllerColumnsShow() {
        this.controlCustomizeColumnDialogForm = true;
        this.$nextTick(() => {
          this.defaultCustomizeColumnList.forEach((row, index) => {
            this.headDatas.forEach((selectedRow) => {
              if (row.label === selectedRow.label) {
                this.defaultCustomizeColumnList[index] = selectedRow;
                this.$refs.customizeColumnList.toggleRowSelection(
                  this.defaultCustomizeColumnList[index],
                  true
                );
              }
            });
          });
        });
      },
      // 弹出窗中表格多选框内容改变触发事件
      handleColumnSelectionChange(selection) {
        this.multipleSelectionColumnList = selection;
      },
      // 添加用户自定义列头
      handleUpdateCustomizeColumn() {
        let param = {
          username: this.userInfo.username,
          resourceType: this.currentResourceTypeName,
          columns: JSON.stringify(this.multipleSelectionColumnList),
        };
        CustomizeColumnApi.updateCustomizeColumn(param).then((res) => {
          if (res.code == 200) {
            this.$message.success(res.message);
            this.reload();
          }
        });
      },
      handleDeleteCustomizeColumn() {
        let param = {
          username: this.userInfo.username,
          resourceType: this.currentResourceTypeName,
        };
        CustomizeColumnApi.deleteCustomizeColumn(param).then((res) => {
          if (res.code == 200) {
            this.$message.success("恢复默认显示成功");
            this.reload();
          }
        });
      },
      // 获取用户自定义列头显示
      getUserCustomizeColumn() {
        CustomizeColumnApi.getCustomizeColumn(
          this.userInfo.username,
          this.currentResourceTypeName
        ).then((res) => {
          this.headDatas = res.data;
        });
      },
      // 获取默认列头信息
      getDefaultCustomizeColumn() {
        CustomizeColumnApi.getCustomizeColumn(
          "default",
          this.currentResourceTypeName
        ).then((res) => {
          this.defaultCustomizeColumnList = res.data;
        });
      },

      // 添加实体弹窗显示
      handleAddInfo() {
        this.editResourceEntityData = {};
        this.editResourceEntityData.resourceTypeName = this.currentResourceTypeName;
        this.editResourceEntityData.resourceTypeTitle = this.currentResourceTypeTitle;

        this.addOrUpdate = "add";
        this.dialogTitle = "添加实体信息";
        this.editResourceEntityDialogForm = true;
      },

      // 点击编辑按钮触发弹窗及赋值
      handleEditInfo(index, row) {
        this.editResourceEntityData = JSON.parse(JSON.stringify(row));
        this.editResourceEntityData.resourceTypeTitle = this.currentResourceTypeTitle;
        this.editResourceEntityData.owner = [];
        this.getUsernameByRealName(row.owner);

        this.addOrUpdate = "update";
        this.dialogTitle = "修改实体信息";
        this.editResourceEntityDialogForm = true;
      },
      // 通过用户真实名获取到用户名
      getUsernameByRealName(realName) {
        this.userList.forEach((userGroup) => {
          userGroup.children.forEach((user) => {
            if (user.label == realName) {
              this.editResourceEntityData.owner = [userGroup.value, user.value];
            }
          });
        });
      },
      // 获取用户组列表
      getUserGroupList() {
        UserGroupApi.getUserGroupList().then((res) => {
          res.data.forEach((userGroup) => {
            let childrenUserLit = [];
            UserApi.getUserListByGroupName(userGroup.userGroupName).then(
              (res) => {
                res.data.forEach((user) => {
                  childrenUserLit.push({
                    value: user.username,
                    label: user.realName,
                  });
                });
              }
            );
            this.userList.push({
              value: userGroup.userGroupName,
              label: userGroup.userGroupName,
              children: childrenUserLit,
            });
          });
        });
      },

      // 判断弹窗当前是添加还是修改
      handleSubmitResourceEntityData() {
        if (this.addOrUpdate === "update") {
          this.handleEditResourceEntityData();
        } else {
          this.handleAddResourceEntityData();
        }
      },

      // 修改资源类别实体信息
      handleEditResourceEntityData() {
        this.$refs.editResourceEntityData.validate((valid) => {
          ResourceTypeEntityApi.updateResourceTypeEntityByEntityId(
            this.editResourceEntityData
          ).then((res) => {
            let entityFieldValue = {
              resourceTypeEntityId: this.editResourceEntityData
                .resourceTypeEntityId,
              resourceTypeName: this.currentResourceTypeName,
            };
            let needToUpdateFieldNum = this.resourceTypeEntityFieldList.length;
            let handledNum = 0;
            this.resourceTypeEntityFieldList.forEach((element) => {
              const fieldName = element.resourceTypeFieldName;
              entityFieldValue.resourceTypeFieldName = fieldName;
              entityFieldValue.resourceTypeEntityDataValue = this.editResourceEntityData[
                fieldName
              ];
              ResourceTypeEntityDataApi.updateResourceTypeEntityDataByEntityIdAndFieldName(
                entityFieldValue
              ).then((res) => {
                handledNum++;
                if (handledNum == needToUpdateFieldNum) {
                  if (this.editResourceEntityData.owner.length > 0) {
                    this.updateUserEntityRelation(
                      this.editResourceEntityData.resourceTypeEntityId
                    );
                  }
                  this.$message.success("修改成功");
                  this.editResourceEntityDialogForm = false;
                }
              });
            });
          });
        });
      },
      // 添加资源实体
      handleAddResourceEntityData() {
        this.$refs.editResourceEntityData.validate((valid) => {
          if (valid) {
            let entityData = {
              resourceTypeName: this.currentResourceTypeName,
              resourceTypeEntityDescription: this.editResourceEntityData
                .resourceTypeEntityDescription,
              status: this.editResourceEntityData.status,
            };
            ResourceTypeEntityApi.addResourceTypeEntity(entityData).then(
              (res) => {
                if (res.data != null) {
                  this.handleAddResourceEntityFieldData(
                    res.data.resourceTypeEntityId
                  );
                }
              }
            );
          }
        });
      },
      // 添加资源实体字段值
      handleAddResourceEntityFieldData(entityId) {
        let entityFieldValue = {
          resourceTypeName: this.currentResourceTypeName,
          resourceTypeEntityId: entityId,
        };
        let needToUpdateFieldNum = this.resourceTypeEntityFieldList.length;
        let handledNum = 0;
        this.resourceTypeEntityFieldList.forEach((element) => {
          const fieldName = element.resourceTypeFieldName;
          entityFieldValue.resourceTypeFieldName = fieldName;
          entityFieldValue.resourceTypeEntityDataValue = this.editResourceEntityData[
            fieldName
          ];
          ResourceTypeEntityDataApi.addResourceTypeEntityData(
            entityFieldValue
          ).then((res) => {
            handledNum++;
            if (handledNum == needToUpdateFieldNum) {
              if (this.editResourceEntityData.owner.length > 0) {
                this.updateUserEntityRelation(entityId);
              }
              this.$message.success("添加成功");
              this.editResourceEntityDialogForm = false;
            }
          });
        });
      },

      // 更新用户实体关系
      updateUserEntityRelation(entityId) {
        let userEntity = {
          entityId: entityId,
          userGroupName: this.editResourceEntityData.owner[0],
          username: this.editResourceEntityData.owner[1],
        };
        UserEntityApi.updateUserEntityByEntityId(userEntity).then((res) => {});
      },

      // 删除实体方法
      handleDeleteEntity(index, row) {
        ResourceTypeEntityApi.markDeleteResourceTypeEntityByEntityId(
          row.resourceTypeEntityId
        ).then((res) => {
          if (res.code == 200) {
            this.$message.success("删除成功");
            this.getResourceTypeEntityDataList();
          } else {
            this.$message.error(res.message);
          }
        });
      },

      // 标签页切换时修改当前资源类别英文名
      handleTabChange() {
        this.pageData.currentPage = 1;

        this.showSearchComponent = false;
        // 重新加载子组件
        this.timer = new Date().getTime();
        this.currentResourceTypeName = this.resourceTypeList[
          this.currentResourceTypeIndex
        ].resourceTypeName;
        this.showSearchComponent = true;

        this.currentResourceTypeTitle = this.resourceTypeList[
          this.currentResourceTypeIndex
        ].resourceTypeTitle;
        this.isShow = false;

        this.getResourceTypeEntityFieldList();
      },

      // 获取资源类别列表
      getResourceTypeList() {
        ResourceTypeApi.getResourceTypeList().then((res) => {
          if (res.code == 200) {
            this.resourceTypeList = res.data;
            this.currentResourceTypeName =
              this.resourceTypeList.length > 0
                ? this.resourceTypeList[0].resourceTypeName
                : "";
            this.currentResourceTypeTitle =
              this.resourceTypeList.length > 0
                ? this.resourceTypeList[0].resourceTypeTitle
                : "";
            this.getResourceTypeEntityFieldList();

            this.showSearchComponent = true;
          }
        });
      },

      // 获取资源类别实体字段列表
      getResourceTypeEntityFieldList() {
        ResourceTypeFieldApi.getResourceTypeFieldByName(
          this.currentResourceTypeName
        ).then((res) => {
          this.resourceTypeEntityFieldList = res.data;
          this.resourceTypeEntityFieldList.forEach((fieldInfo) => {
            if (fieldInfo.resourceTypeFieldType == "enum") {
              EnumApi.getEnumItemByGroupName(fieldInfo.enumGroupName).then(
                (res) => {
                  this.$set(fieldInfo, "enumItemList", res.data);
                }
              );
            }
          });
          // 获取资源实体数据
          this.getResourceTypeEntityDataList();
          this.isShow = true;

          // 获取用户自定义列头显示
          this.getUserCustomizeColumn();
          // 获取默认展示列头
          this.getDefaultCustomizeColumn();
        });
      },

      // 获取表格数据
      getResourceTypeEntityDataList() {
        let queryEntityDtoList = [
          {
            dynamics: true,
            fieldName: "group",
            fieldType: "enum",
            fieldValue: this.userGroupName,
            isDynamics: true,
            tableName: "resource_type_field",
          },
        ];
        this.queryParam = {
          resourceTypeName: this.currentResourceTypeName,
          currentPage: this.pageData.currentPage,
          pageSize: this.pageData.pageSize,
          queryEntityDtoList: queryEntityDtoList,
        };
        ResourceTypeEntityApi.queryResourceEntityPageList(this.queryParam).then(
          (res) => {
            this.resourceTypeEntityDataList = res.data.pageDataList;
            this.pageData.total = res.data.totalSize;
            // 获取资源实体动态字段数据
            this.getResourceTypeEntityFieldData();
          }
        );
      },

      // 搜索数据方法
      queryEntityList(queryParam, isComponent) {
        if (isComponent) {
          this.pageData.currentPage = 1;
        }
        let queryDynamicsParam = queryParam.queryEntityDtoList;
        queryDynamicsParam.push({
          dynamics: true,
          fieldName: "group",
          fieldType: "enum",
          fieldValue: this.userGroupName,
          isDynamics: true,
          tableName: "resource_type_field",
        });
        this.queryParam = {
          resourceTypeName: this.currentResourceTypeName,
          currentPage: this.pageData.currentPage,
          pageSize: this.pageData.pageSize,
          queryEntityDtoList: queryDynamicsParam,
        };
        ResourceTypeEntityApi.queryResourceEntityPageList(this.queryParam).then(
          (res) => {
            this.removeGroupField();
            this.resourceTypeEntityDataList = res.data.pageDataList;
            this.pageData.total = res.data.totalSize;
            // 获取资源实体动态字段数据
            this.getResourceTypeEntityFieldData();
          }
        );
      },
      removeGroupField() {
        let groupIndex = -1;
        let queryParam = this.queryParam.queryEntityDtoList;
        for (let index = 0; index < queryParam.length; index++) {
          if (queryParam[index].fieldName === "group") {
            groupIndex = index;
          }
        }
        if (groupIndex != -1) {
          this.queryParam.queryEntityDtoList.splice(groupIndex, 1);
        }
      },

      // 获取资源实体动态字段数据
      getResourceTypeEntityFieldData() {
        if (this.resourceTypeEntityDataList != null) {
          this.resourceTypeEntityDataList.forEach((element) => {
            ResourceTypeEntityDataApi.getResourceTypeEntityDataByEntityId(
              element.resourceTypeEntityId
            ).then((res) => {
              res.data.forEach((value) => {
                this.$set(
                  element,
                  value.resourceTypeFieldName,
                  value.resourceTypeEntityDataValue
                );
              });
            });

            UserEntityApi.getUserEntityByEntityId(
              element.resourceTypeEntityId
            ).then((res) => {
              this.$set(
                element,
                "owner",
                res.data == null ? "" : res.data.username
              );
            });
          });
        }
      },

      // 设置表格样式
      getHeadClass({ rowIndex }) {
        if (rowIndex == 0) {
          return "background-color:#ccc;color:#fff;font-size:30px;";
        }
      },
      getRowClassName({ row, rowIndex }) {
        if (rowIndex % 2 !== 0) {
          return "warning-row";
        }
      },

      // 格式化时间
      formatterTime(row, column, cellValue, index) {
        return cellValue.substring(0, cellValue.lastIndexOf("."));
      },

      // 格式化状态
      formatterStatus(row, column, cellValue, index) {
        let stat = cellValue;
        usingStatus.forEach((status) => {
          if (status.key == cellValue) {
            stat = status.value;
          }
        });
        return stat;
      },
      // 格式化是否可申请
      formatterMayApply(row, column, cellValue, index) {
        let apply = "否";
        if (cellValue) {
          apply = "是";
        }
        return apply;
      },
      formatterNothing(row, column, cellValue, index) {
        return cellValue;
      },

      // 当前页发生改变
      handleCurrentChange(val) {
        this.pageData.currentPage = val;
        this.queryEntityList(this.queryParam, false);
      },
      // 当前页大小发生改变
      handleSizeChange(val) {
        this.pageData.currentPage = 1;
        this.pageData.pageSize = val;
        this.queryEntityList(this.queryParam, false);
      },
      // 搜索全部空闲资源
      searchAllFreeResource() {
        let param = {
          queryEntityDtoList: [
            {
              fieldName: "status",
              fieldValue: "free",
              fieldType: "enum",
              dynamics: false,
              tableName: "resource_type_entity",
            },
            {
              dynamics: true,
              fieldName: "group",
              fieldType: "enum",
              fieldValue: this.userGroupName,
              isDynamics: true,
              tableName: "resource_type_field",
            },
          ],
        };
        this.pageData.currentPage = 1;
        this.queryEntityList(param, false);
      },

      // 搜索全部可申请资源
      searchAllCouldApplyResource() {
        let param = {
          queryEntityDtoList: [
            {
              fieldName: "mayApply",
              fieldValue: "true",
              fieldType: "enum",
              dynamics: false,
              tableName: "resource_type_entity",
            },
            {
              dynamics: true,
              fieldName: "group",
              fieldType: "enum",
              fieldValue: this.userGroupName,
              isDynamics: true,
              tableName: "resource_type_field",
            },
          ],
        };
        this.pageData.currentPage = 1;
        this.queryEntityList(param, false);
      },
    },

    computed: {
      ...mapGetters({
        permissions: "user/permissions",
        realName: "user/username",
        userInfo: "user/userInfo",
      }),
    },

    mounted() {
      this.getUserGroupList();
      this.usingStatus = usingStatus;
    },

    created() {
      this.getResourceTypeList();
    },
  };
</script>
